import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime'
import 'dayjs/locale/zh-cn'
import Modal from '../components/modal.vue'

// 睡眠函数
const $sleep = (time) => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve()
    }, time || 2000)
  })
}
// 注册全局相对时间过滤器(dayjs)
// 国际化
dayjs.locale('zh-cn')
// 添加这个插件才能用from方法
dayjs.extend(relativeTime)
const relTime = (val) => {
  return dayjs().from(val)
}

export default {
  install (Vue) {
    Vue.prototype.$sleep = $sleep
    Vue.filter('reltime', relTime)
    Vue.component('Modal', Modal)
  }
}
